package outlookBar;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JComponent;

/**
 * This is the base clase for the section headers.<br/>
 * It must fire an java.awt.event.ActionEvent to notify the bar to show the section
 * @see #OutlookBar
 * @see #BarSection
 * @author Carlos E. Descalzi
 */
public abstract class BarHeader extends JComponent {

	private List<ActionListener> listeners = new ArrayList<ActionListener>();
	
	
	public synchronized void addActionListener(ActionListener listener){
		if (!listeners.contains(listener)){
			ArrayList<ActionListener> listeners = new ArrayList<ActionListener>(this.listeners);
			listeners.add(listener);
			this.listeners = listeners;
		}
	}

	public synchronized void removeActionListener(ActionListener listener){
		if (listeners.contains(listener)){
			ArrayList<ActionListener> listeners = new ArrayList<ActionListener>(this.listeners);
			listeners.remove(listener);
			this.listeners = listeners;
		}
	}
	
	protected void fireActionPerformed(Object source){
		ActionEvent event = new ActionEvent(source,ActionEvent.ACTION_PERFORMED,"action");
		for (ActionListener listener:listeners){
			listener.actionPerformed(event);
		}
	}

}
